package com.neuedu.hisboot.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.neuedu.hisboot.dto.DoctorScheduleDTO;
import com.neuedu.hisboot.entity.Scheduling;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author jaun
 * @since 2025-07-04
 */
@Mapper
public interface SchedulingMapper extends BaseMapper<Scheduling> {

    @Select("<script>" +
            "SELECT " +
            "s.SchedDate AS schedDate, " +
            "d.DeptName AS deptName, " +
            "u.RealName AS realName, " +
            "s.Noon AS noon, " +
            "r.RegistName AS registName, " +
            "r.RegistFee AS registFee, " +
            "r.RegistQuota AS registQuota " +
            "FROM scheduling s " +
            "INNER JOIN user u ON s.UserID = u.ID " +
            "INNER JOIN department d ON s.DeptID = d.ID " +
            "INNER JOIN registlevel r ON u.RegistLeID = r.ID " +
            "WHERE " +
            "d.ID = #{deptId} " +
            "AND u.ID = #{userId} " +
            "<if test='registLevelId != null'>" +
            "   AND r.ID = #{registLevelId} " +
            "</if>" +
            "AND s.DelMark = 1 " +
            "AND u.DelMark = 1 " +
            "AND d.DelMark = 1 " +
            "AND r.DelMark = 1" +
            "</script>")
    List<DoctorScheduleDTO> findDoctorSchedules(
            @Param("deptId") Integer deptId,
            @Param("userId") Integer userId,
            @Param("registLevelId") Integer registLevelId);

}
